package com.sgb.kjwl.view.ui.activity.enterprise;

import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPerfessionalTeamChangeBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.view.ui.adapter.home.ViewPagerAdapter;
import com.sgb.kjwl.view.ui.fragment.enterprise.ProfessionalTeamFragment2;
import com.sgb.kjwl.viewmodel.enterprise.ProfessionalTeamChangeModel;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;


public class ProfessionalTeamChangeActivity extends AppActivity {
    ActivityPerfessionalTeamChangeBinding mBinding;

    @Inject
    ProfessionalTeamChangeModel mModel;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_perfessional_team_change);
        mBinding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                TextView selectTextView = new TextView(getActivity());
                selectTextView.setTextSize(15);
                selectTextView.setTextColor(getResources().getColor(R.color.color_main));
                selectTextView.setText(tab.getText());
                selectTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tab.setCustomView(selectTextView);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        mModel.getServiceType();
    }

    private void initTab(List<IpPickSelectEntity> title) {
        List<Pair<String, Fragment>> mList = new ArrayList<>();
        for (IpPickSelectEntity s : title) {
            Bundle bundle = new Bundle();
            ProfessionalTeamFragment2 couponFragment = new ProfessionalTeamFragment2();
            bundle.putString("code", s.getValue());
            couponFragment.setArguments(bundle);
            mList.add(new Pair<>(s.getName(), couponFragment));
        }
        mBinding.vpNeed.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), mList));
        mBinding.vpNeed.setOffscreenPageLimit(title.size());
        mBinding.tab.setupWithViewPager(mBinding.vpNeed);
        mBinding.tab.getTabAt(0).select();
    }

    public void getAllCategory(List<IpPickSelectEntity> list) {
        initTab(list);
    }

}

